<?php

namespace app\common\model\xilujob;

use think\Cache;
use think\Model;


class Salary extends Model
{

    const TYPE_HOUR = 1;
    const TYPE_DAILY = 2;
    const TYPE_MONTH = 3;

    

    // 表名
    protected $name = 'xilujob_salary';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'option_type_text'
    ];
    

    
    public function getOptionTypeList()
    {
        return ['1' => __('Option_type 1'), '2' => __('Option_type 2'), '3' => __('Option_type 3')];
    }


    public function getOptionTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['option_type']) ? $data['option_type'] : '');
        $list = $this->getOptionTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public static function getHourOptions() {
        $cacheKey = 'hour_salary_options';
        $all = Cache::get($cacheKey);
        if(!$all) {
            $all = static::where('option_type',self::TYPE_HOUR)->order('min')->select();
            Cache::set($cacheKey, $all, 3600);
        }
        return $all;
    }

    public static function getDailyOptions() {
        $cacheKey = 'daily_salary_options';
        $all = Cache::get($cacheKey);
        if(!$all) {
            $all = static::where('option_type',self::TYPE_DAILY)->order('min')->select();
            Cache::set($cacheKey, $all, 3600);
        }
        return $all;
    }


    public static function getMonthOptions() {
        $cacheKey = 'month_salary_options';
        $all = Cache::get($cacheKey);
        if(!$all) {
            $all = static::where('option_type',self::TYPE_MONTH)->order('min')->select();
            Cache::set($cacheKey, $all, 3600);
        }
        return $all;
    }


}
